# Contributor: stef <l0ls0fo2i@ctrlc.hu>
# Contributor: Bradley J Chambers <brad.chambers@gmail.com>
# Maintainer: Bradley J Chambers <brad.chambers@gmail.com>
pkgname=eigen
pkgver=3.3.7
pkgrel=3
pkgdesc="Eigen is a C++ template library for linear algebra"
url="http://eigen.tuxfamily.org/index.php?title=Main_Page"
arch="noarch !mips !mips64"
license="MPL-2.0"
options="!check"  # checks take a long time, and tend to fail randomly
makedepends="cmake openblas-dev suitesparse-dev mpfr-dev fftw-dev boost-dev gmp-dev glu-dev freeglut-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::http://bitbucket.org/eigen/eigen/get/$pkgver.tar.gz
	fftw-test-fix.patch
	fix-build.patch
	"
builddir="$srcdir/$pkgname-$pkgname"

prepare() {
	mv "$builddir"-* "$builddir"  # directory name contains hash
	default_prepare
}

build() {
	# needs -std so c11 tests are being built
	CXXFLAGS="$CXXFLAGS -std=c++11" \
	cmake -B build . \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None
	make -C build
}

check() {
	make -C build check
}

package() {
	make -C build DESTDIR="$pkgdir" install

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	cp -r "$builddir"/doc/ "$pkgdir"/usr/share/doc/$pkgname
	mkdir -p $pkgdir/usr/lib/pkgconfig
	mv $pkgdir/usr/share/pkgconfig/eigen3.pc $pkgdir/usr/lib/pkgconfig
}

dev() {
	default_dev
	mkdir -p $subpkgdir/usr/share/cmake/Modules
	mv $pkgdir/usr/share/eigen3/cmake/*.cmake $subpkgdir/usr/share/cmake/Modules
}

sha512sums="34cf600914cce719d61511577ef9cd26fbdcb7a6fad1d0ab8396f98b887fac6a5577d3967e84a8f56225cc50de38f3b91f34f447d14312028383e32b34ea1972  eigen-3.3.7.tar.gz
c1f9d7d8c9025b4b2b3a679f80519e494f206d7bee232cd10dd45df454b1ce6697858547bc0d956a5818481d344948704db8dbb39d04ac69ff7de99961492384  fftw-test-fix.patch
496e2b61a5fd319218338a6891dade420efa14aecd92fb9007ebf924a28e01298fa3ab5fb8c86ce02f1aa820e60ef47b18b5663d1ce316f9f1ac119b83387459  fix-build.patch"
